/**   
 * @Title: NewsDetailActivity.java 
 * @Package cn.edu.scu.healthclient.activity 
 * @Description: TODO 
 * @author 
 * @date 
 * @version V0.0   
 */
package cn.edu.cdtu.healthclient.activity;

import android.app.Activity;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.Window;
import android.widget.TextView;
import cn.edu.cdtu.healthclient.domain.HealthNewsJson;
import cn.edu.cdtu.healthclient.service.HealthService;
import cn.edu.cdtu.healthclient.service.HealthService.HealthBinder;
import cn.edu.cdtu.healthclient.task.ActivityTaskQueue;
import cn.edu.scu.healthclient.activity.R;

/** 
 * @ClassName: NewsDetailActivity 
 * @Description: TODO
 * @author 
 * @date 
 *  
 */
public class NewsDetailActivity extends Activity {
	
	/*
	 * 
	 */
	private ActivityTaskQueue taskQueue;
	public ActivityTaskQueue getTaskQueue(){
		return taskQueue;
	}
	/*
	 * 
	 */
	private HealthBinder binder;
	public HealthBinder getBinder(){
		return binder;
	}
	/*
	 * 
	 */
	private ServiceConnection serviceConnection = new ServiceConnection() {
		
		@Override
		public void onServiceDisconnected(ComponentName name) {
			// TODO Auto-generated method stub
			binder = null;
			taskQueue.shutdownTaskQueue();
		}
		
		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			// TODO Auto-generated method stub
			binder = (HealthBinder)service;
			if(!taskQueue.isRunning()){
				taskQueue.start();
			}
		}
	};
	/*
	 * 
	 */
	private final Intent serviceIntent = new Intent(HealthService.ACTION);
	
	private TextView p1,p2,p3,p4,p5;
	private HealthNewsJson healthNewsJson;
	
	/* (non-Javadoc)
	 * <p>Title: onCreate</p> 
	 * <p>Description: </p> 
	 * @param savedInstanceState 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		startService(serviceIntent);
    	taskQueue = new ActivityTaskQueue();
//    	this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//				WindowManager.LayoutParams.FLAG_FULLSCREEN);  
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_news_detail);
		p1=(TextView)findViewById(R.id.p1);
		p2=(TextView)findViewById(R.id.p2);
		p3=(TextView)findViewById(R.id.p3);
		p4=(TextView)findViewById(R.id.p4);
		p5=(TextView)findViewById(R.id.p5);
		Intent newsDetialIntent=getIntent();
		healthNewsJson=(HealthNewsJson)newsDetialIntent.getSerializableExtra("healthNewsJson");
		p1.setText(healthNewsJson.getParagraph1());
		p2.setText(healthNewsJson.getParagraph2());
		p3.setText(healthNewsJson.getParagraph3());
		p4.setText(healthNewsJson.getParagraph4());
		p5.setText(healthNewsJson.getParagraph5());
	}

	/* (non-Javadoc)
	 * <p>Title: onStart</p> 
	 * <p>Description: </p>  
	 * @see android.app.Activity#onStart()
	 */
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		bindService(serviceIntent, 
        		serviceConnection, Service.BIND_AUTO_CREATE);
		super.onStart();
	}

	/* (non-Javadoc)
	 * <p>Title: onStop</p> 
	 * <p>Description: </p>  
	 * @see android.app.Activity#onStop()
	 */
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		unbindService(serviceConnection);
	}
	
	
}
